package com.swpu.cbg.cnshop.utils;

import android.content.Context;
import android.text.TextUtils;

import com.swpu.cbg.cnshop.Constans;
import com.swpu.cbg.cnshop.bean.User;


public class UserLocalData {



    public static void putUser(Context context,User user){


        String user_json =  JsonUtil.toJSON(user);
        SharperenceUtil.putString(context, Constans.USER_JSON,user_json);

    }

    public static void putToken(Context context,String token){

        SharperenceUtil.putString(context, Constans.TOKEN,token);
}


    public static User getUser(Context context){

        String user_json= SharperenceUtil.getString(context,Constans.USER_JSON);
        if(!TextUtils.isEmpty(user_json)){

            return  JsonUtil.fromJson(user_json,User.class);
        }
        return  null;
    }

    public static  String getToken(Context context){

        return  SharperenceUtil.getString( context,Constans.TOKEN);

    }


    public static void clearUser(Context context){


        SharperenceUtil.putString(context, Constans.USER_JSON,null);

    }

    public static void clearToken(Context context){

        SharperenceUtil.putString(context, Constans.TOKEN,null);
    }



}
